package com.ye.personnel.controller;

import com.ye.personnel.api.user.*;
import com.ye.personnel.common.response.BaseResult;
import com.ye.personnel.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;


/**
 * @Author: yeubo
 * @Date: 2023/11/9 11:27
 */
@RestController
@RequestMapping("common")
@Api(tags = "公共模块")
public class CommonController {

    @Autowired
    CommonService commonService;

    @PostMapping("userLogin")
    @ApiOperation("用户登录")
    public BaseResult<LoginResultVo> userLogin(@Validated @RequestBody UserLoginDto loginDto){
        LoginResultVo resultVo = commonService.userLogin(loginDto);
        return new BaseResult<LoginResultVo>().ok(resultVo);
    }

    @PostMapping("/uploadFile")
    @ApiOperation("文件上传")
    public BaseResult<Map<String,String>> uploadFiles(@RequestPart("file") MultipartFile file) {
        Map<String, String> map = commonService.uploadFileToLocal(file);
        return new BaseResult<Map<String,String>>().ok(map);
    }

    @GetMapping("flowTypeList")
    @ApiOperation("发起类型列表")
    public BaseResult<FlowTypeVo> flowTypeList(){
        FlowTypeVo flowTypeVo = commonService.flowTypeList();
        return new BaseResult<FlowTypeVo>().ok(flowTypeVo);
    }


    @GetMapping("userTypeList")
    @ApiOperation("用户类型列表")
    public BaseResult<List<UserTypeListVo>> userTypeList(){
        List<UserTypeListVo> userTypeListVos = commonService.userTypeList();
        return new BaseResult<List<UserTypeListVo>>().ok(userTypeListVos);
    }

    @GetMapping("pullDepartment")
    @ApiOperation("拉取部门")
    public BaseResult<String> pullDepartment(){
        commonService.pullDepartment();
        return new BaseResult<String>().ok("success");
    }

}
